package org.ycx.doc.service.impl;

import org.ycx.common.annotation.BaseService;
import org.ycx.common.base.BaseServiceImpl;
import org.ycx.doc.dao.mapper.IDocModuleMapper;
import org.ycx.doc.dao.mapper.IDocProjectMapper;
import org.ycx.doc.dao.model.DocModule;
import org.ycx.doc.dao.model.DocModuleExample;
import org.ycx.doc.dao.model.DocProject;
import org.ycx.doc.service.IDocModuleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* DocModuleService实现
* Created by yang on 2017-08-30 17:02:41.
*/
@Service
@Transactional
@BaseService
public class DocModuleServiceImpl extends BaseServiceImpl<IDocModuleMapper, DocModule, DocModuleExample> implements IDocModuleService {

    private static Logger _log = LoggerFactory.getLogger(DocModuleServiceImpl.class);

    @Autowired
    IDocModuleMapper mapper;

    @Autowired
    IDocProjectMapper projectMapper;

    @Override
    public List<DocModule> selectByAppIdAndVersion(Integer appId, Integer version) {
        if(version == null){
            DocProject bean = this.projectMapper.selectByPrimaryKey (appId);
            version = bean.getAppProdVersion ();
        }
        if(version == 0){
            return this.mapper.selectByAppIdNoVersion(appId);
        }else{
            return this.mapper.selectByAppIdAndVersion(appId,version);
        }
    }
}